package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Title: ShoppingCartMapper
 * @Author 贾金博
 * @Package com.sky.mapper
 * @Date 2024/3/29 11:52
 * @description:
 */
@Mapper
public interface ShoppingCartMapper {
    List<ShoppingCart> list (ShoppingCart shoppingCart);

    /**
     * 修改商品的数量的
     * @param cart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart cart);


    /**
     * 插入购物车数据
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) " +
            "values (#{name}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount}, #{image}, #{createTime})")
    void insert(ShoppingCart shoppingCart);


    /**
     * 根据userId清空购物车
     * @param id
     */
    @Delete("delete from shopping_cart where user_id = #{id}")
    void deleteById(Long id);

    /**
     * 根据菜品进行撒删除
     * @param cart
     */
    void deleyteByCart(ShoppingCart cart);
}
